package ink.tiptop.common.worker.hotdata;

import ink.tiptop.service.ZjfBaseServerInfoService;
import ink.tiptop.service.ZjfModuleLocalService;
import ink.tiptop.service.ZjfServiceRemoteViewService;
import ink.tiptop.utils.async.executor.Async;
import ink.tiptop.utils.async.wrapper.WorkerWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Observable;

/**
 * @author ink.tiptop.zjf
 * @Title: Ticket
 * @Package ink.tiptop.common.worker.heat
 * @Description:    预加热数据
 * @date 2020-07-31 14:52
 */
@Component("heatData")
@Slf4j
public class HotData extends Observable implements InitializingBean {

    @Autowired
    private ZjfModuleLocalService moduleLocalService;

    @Autowired
    private ZjfBaseServerInfoService baseServerInfoService;

    @Autowired
    private ZjfServiceRemoteViewService serviceRemoteViewService;

    @Override
    public void afterPropertiesSet() throws Exception {
        HotData observable = new HotData();
        observable.addObserver(moduleLocalService);
        observable.addObserver(baseServerInfoService);
        observable.addObserver(serviceRemoteViewService);
        observable.setChanged();

        HotDataWorker hotDataWorker = new HotDataWorker();
        WorkerWrapper<Observable, Boolean> workerWrapper = new WorkerWrapper.Builder<Observable, Boolean>()
                .worker(hotDataWorker)
                .callback(hotDataWorker)
                .param(observable)
                .build();
        Async.beginWork(3000, workerWrapper);
    }
}
